import {Controller, Get, UseGuards, Post, Body, Param, Query} from '@nestjs/common';
import { AccountService } from '@/modules/account/account.service';
import {JwtAuthGuard} from "@/modules/auth/jwt-auth.guard";
import { IWonewSer } from '@/typing';

@Controller("account")
export class AccountController {
  constructor(
    private readonly accountService: AccountService
  ) {
  }

  @Get("/list")
  @UseGuards(JwtAuthGuard)
  getList(@Query() query: IWonewSer.QueryFilterParams) {
    return this.accountService.getList(query)
  }

  @Post("/create")
  @UseGuards(JwtAuthGuard)
  create(@Body() body: {name: string, type: number}) {
    return this.accountService.createOrEdit(0, body)
  }

  @Post("/:id/update")
  @UseGuards(JwtAuthGuard)
  update(@Param("id") id: number, @Body() body: {name: string, type: number}) {
    return this.accountService.createOrEdit(id, body)
  }

  @Post("/:id/delete")
  @UseGuards(JwtAuthGuard)
  delete(@Param("id") id: number) {
    return this.accountService.delete(id)
  }

  @Post("/:id/update-hook-user-action")
  @UseGuards(JwtAuthGuard)
  updateHookUserAction(@Param("id") id: number) {
    return this.accountService.updateHookUserAction(id)
  }

  @Get("/:id/fire-hook-user-action")
  fireHookUserAction(@Param("id") id: number) {
    return this.accountService.fireHookUserAction(id)
  }

  @Get("/:id/cookie")
  getCookie(@Param("id") id: number) {
    return this.accountService.getCookie(id)
  }

  @Get("/:id/posts")
  @UseGuards(JwtAuthGuard)
  getPosts(@Param("id") id: number, @Query() opt?: IWonewSer.PaginationPrams & {max_cursor?: string}) {
    return this.accountService.getPosts(id, opt)
  }

  @Get("/:id/bind/prepare")
  @UseGuards(JwtAuthGuard)
  bindPrepare(@Param("id") id: number) {
    return this.accountService.bindPrepare(id)
  }

  @Get("/:id/bind/check")
  @UseGuards(JwtAuthGuard)
  bindCheck(@Param("id") id: number, @Query() query: {hash: string}) {
    return this.accountService.bindCheck(id, query)
  }

  @Get("/:id/check-cookie")
  // @UseGuards(JwtAuthGuard)
  checkCookie(@Param("id") id: number) {
    return this.accountService.checkCookie({id})
  }

  @Get("/:id/open-home-page")
  // @UseGuards(JwtAuthGuard)
  openHomePage(@Param("id") id: number) {
    return this.accountService.openHomePage(id)
  }
  @Get("/close-home-page/:hashId")
  // @UseGuards(JwtAuthGuard)
  closeHomePage(@Param("hashId") hashId: string) {
    return this.accountService.closeHomePage(hashId)
  }

  @Post("/:id/sms/send")
  @UseGuards(JwtAuthGuard)
  sysSend(@Param("id") id: number) { 
    return this.accountService.dySmsSend(id)
  }

  @Post("/:id/sms/validate")
  @UseGuards(JwtAuthGuard)
  sysValidate(@Param("id") id: number, @Query() query: {code: string}) {
    return this.accountService.dySmsValidate(id, query.code)
  }

  @Post("/:id/share/cookie")
  @UseGuards(JwtAuthGuard)
  shareCookie(@Param("id") id: number, @Body() data: {cookie: string}) {
    return this.accountService.shareCookie(id, data.cookie)
  }

  @Get("/type_vars")
  getTypeVars() {
    return this.accountService.getTypeVars()
  }
}